﻿using System;
using Uinside.CreditSystem.DomainModels.Models;

namespace Uinside.CreditSystem.WPF.ViewModels
{
    public class CompanyWorkspaceViewModel : CustomersWorkspaceVIewMode
    {
        public override bool IsCompany
        {
            get { return true; }
        }

        private object _lock = new Object();

        private Customer _currentItem;
        public override Customer CurrentItem
        {
            get
            {
                if (_currentItem == null)
                {
                    SetBusyState(true);
                    RunBackgroundWorker((s, e) =>
                    {
                        lock (_lock)
                        {
                            Console.WriteLine(1);
                            if (_currentItem == null)
                            {
                                Console.WriteLine(2);
                                _currentItem = CustomerService.GetCompany();

                            }
                            Console.WriteLine(3);
                        }
                    }, (s, e) =>
                    {
                        OnPropertyChanged("CurrentItem");
                        SetBusyState(false);
                    });
                }
                return _currentItem;
            }
            set
            {
                _currentItem = value;
                OnPropertyChanged("CurrentItem");
            }
        }
    }
}
